<script>
   $(document).ready(function(){
      $("#submit").click(function(){
         var username = $("#username").val();
         var password = $("#password").val();
         var iid = $("#iid").val();
         var role = $("#role").val();
         var name = $("#name").val();
         if(iid=='0'){
	         if(username==""){
	             $("#username_notice").html('');
	             $("#username_notice").html('用户名不能空');
	             return false;
	         }else{
	        	 $.ajax({
	    	    	   type: "POST",
	    	    	   url: "<?php echo base_url();?>administrator/admin_auth",
	    	    	   data: "username="+username,
	    	    	   success: function(msg){
	    		    	   if(msg>=1){
	                         $("#username_notice").html('用户名已存在');
	                         return false;
	    			       }else{
	                         $("#username_notice").html('');
	        			   }
	    	    	   }
	    	    	}); 
	         }
         }
         if(password==""){
             $("#password_notice").html('');
             $("#password_notice").html('密码不能空');
             return false;
         }else{
        	 $("#password_notice").html('');
         }
         if(role==""){
             $("#role_notice").html('');
             $("#role_notice").html('请选择角色');
             return false;
         }else{
        	 $("#role_notice").html('');
         }
         if(name==""){
             $("#name_notice").html('');
             $("#name_notice").html('真实姓名不能空');
             return false;
         }else{
        	 $("#name_notice").html('');
         }
         
      }) 

      $("#username").blur(function(){
          var username = $(this).val();
          $.ajax({
	    	   type: "POST",
	    	   url: "<?php echo base_url();?>administrator/admin_auth",
	    	   data: "username="+username,
	    	   success: function(msg){
		    	   if(msg>=1){
                       $("#submit").attr('disabled',true);
                       $("#username_notice").html('用户名已存在');
			       }else{
			    	   $("#submit").attr('disabled',false);
			    	   $("#username_notice").html('');
  			      }
	    	   }
	    	}); 
      })
   })
</script>
		<div id="center-column">
			<div class="top-bar">
				<?php  if($user[0]->role==0){ ?><a href="<?php echo  base_url();?>administrator/admin_add" class="button">新增</a><?php }?>
				<h1>Contents</h1>
				<div class="breadcrumbs"><a href="#">用户管理</a> /<?php if($user[0]->role==0){echo anchor('administrator/admin','添加用户管理');}?></div>
			</div>
			
		  <div class="table add_table">
				
				<table class="listing form" cellpadding="0" cellspacing="0">
				<?php if(isset($id)){?><input type="hidden" id="iid" value="<?php echo $id;?>" /><?php }else{?><input type="hidden" id="iid" value="0" /><?php }?>
				  <?php if(isset($id)){echo form_open('administrator/admin_edit/'.$id);}else{echo form_open('administrator/admin_add');}?>
					<tr>
						<td class="full">用户名</td>
						<td class="last"><input type="text" class="text" name="username" value="<?php if(isset($id)){echo $admin->username;}?>" id="username" <?php if(isset($id)){?>disabled=true<?php }?>  /><span id="username_notice" style="color:#FF0000;padding-left:5px;">*</span></td>
					</tr>

					<tr>
						<td class="full">密码</td>
						<td class="last"><input type="password" class="text" name="password" value="<?php if(isset($id)){echo $admin->password;}?>" id="password"/><span id="password_notice" style="color:#FF0000;padding-left:5px;">*</span></td>
					</tr>

					<tr>
						<td class="full">角色</td>
						<td class="last">
						<?php if(isset($id)){ if(($user[0]->admin_id==$admin->admin_id)){ ?><input type="hidden" name="role" value="0" /><?php } }?>
						<select name="role" id="role" <?php if(isset($id)){ if(($user[0]->admin_id==$admin->admin_id)){ ?>disabled=true<?php } }?>>
						<option value="">请选角色</option>
						<option value="0" <?php if(isset($id)){ if($admin->role==0){?>selected=true<?php }}?>>管理员</option>
						<option value="1" <?php if(isset($id)){ if($admin->role==1){?>selected=true<?php }}?>>用户</option>
						</select><span id="role_notice" style="color:#FF0000;padding-left:5px;">*</span>
						</td>
					</tr>
					<tr>
						<td class="full">真实姓名</td>
						<td class="last"><input type="text" class="text" name="name" value="<?php if(isset($id)){echo $admin->name;}?>" id="name"/>
						<span id="name_notice" style="color:#FF0000;padding-left:5px;">*</span></td>
					</tr>

					<tr>
						<td class="full">部门</td>
						<td class="last"><input type="text" class="text" name="department" value="<?php if(isset($id)){echo $admin->department;}?>" id="department"/>
						<span id="department_notice"></span></td>
					</tr>

					<tr>
						<td class="full">职务</td>
						<td class="last"><input type="text" class="text" name="post" value="<?php if(isset($id)){echo $admin->post;}?>" id="post"/>
						<span id="post_notice"></span></td>
					</tr>

					<tr>
						<td class="full">职称</td>
						<td class="last"><input type="text" class="text" name="title" value="<?php if(isset($id)){echo $admin->title;}?>" id="title"/>
						<span id="title_notice"></span></td>
					</tr>

					<tr class="bg">
						<td class="full">备注</td>
						<td class="last"><textarea name="remarks" cols="80" rows="5"><?php if(isset($id)){echo $admin->remarks;}?></textarea></td>
					</tr>
					<tr class="bg">
						<td colspan="2" style="text-align:center;"><input type="submit" value="提交" class="button" id="submit" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="返回" class="button" <?php if($user[0]->role==0){ ?>onclick="location.href='<?php echo site_url()?>administrator/admin'" <?php }else{?>onclick="location.href='<?php echo site_url()?>administrator/admin_detail/<?php echo $user[0]->admin_id;?>'"<?php }?> /></td>			
					</tr>
				</form>	
				</table>
	        <p>&nbsp;</p>
		  </div>
		</div>
	</div>
	<div id="footer"></div>
</div>
</body>
</html>

